package com.czl.module_storehouse.adapter;

import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.module_base.utils.NumberUtils;
import com.czl.module_storehouse.R;
import com.czl.module_storehouse.activity.intostore.saveloc.LocationInfoActivity;
import com.czl.module_storehouse.bean.StorageSortViewListBean;
import com.lihang.ShadowLayout;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class RecordInfoAdapter extends BaseQuickAdapter<StorageSortViewListBean, BaseViewHolder> {

    public RecordInfoAdapter(int layoutResId, @Nullable List<StorageSortViewListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, StorageSortViewListBean item) {
        helper.setText(R.id.tv_add_name, item.getSortName())
                .setText(R.id.tv_model, item.getSortModel())
                .setText(R.id.et_num, NumberUtils.decimalPoints(item.getPrice()))
                .setText(R.id.tv_date, item.getManufactureDate())
                .setText(R.id.tv_num, String.valueOf(item.getStorageNum()))
                .setText(R.id.tv_vendor, item.getManufacturer())
                .setText(R.id.tv_product_loc, item.getLocText());
        helper.getView(R.id.tv_product_loc)
                .setOnClickListener(v -> nextLocationInfoActivity(item));
        helper.getView(R.id.iv_next)
                .setOnClickListener(v -> nextLocationInfoActivity(item));
        ShadowLayout shadowLayout = helper.getView(R.id.shadowLayout);
        shadowLayout.setShadowHiddenTop(helper.getLayoutPosition() != 0);
    }

    private void nextLocationInfoActivity(StorageSortViewListBean item) {
        EventBus.getDefault().postSticky(item);
        getContext().startActivity(new Intent(getContext(), LocationInfoActivity.class));
    }
}
